"setup"
setwd("D:/CAV-Reduced")
AV = read.csv("AV.csv");
HV = read.csv("HV.csv");
par(mfrow=c(1,2))

"plot seperate"
headwayAV<-density(AV$headft)
  plot(headwayAV,main="AV Headway (ft)")
speedAV<-density(AV$speedmph)
  plot(speedAV,main="AV Speed (mph)")

headwayHV<-density(HV$headft)
  plot(headwayHV,main="HV Headway (ft)")
speedHV<-density(HV$speedmph)
  plot(speedHV,main="HV Speed (mph)")

"plot together"
plot(headwayAV,main="Headway (ft)",col="red")
  lines(headwayHV,col="blue")
  legend(900,0.004,legend=c("headwayHV","headwayAV"),
         col=c("blue","red"), lty=1:1,cex=0.8)

plot(speedHV,main="Speed (mph)",col="blue")
  lines(speedAV,col="red")
  legend(65,0.06,legend=c("headwayHV","headwayAV"),
         col=c("blue","red"), lty=1:1,cex=0.8)

"plot time headway"
timeheadAV<-density(AV$timeheads)
  plot(timeheadAV,main="AV Time Headway (s)")

timeheadHV<-density(HV$timeheads)
  plot(timeheadHV,main="HV Time Headway (s)")

par(mfrow=c(1,1))
plot(timeheadHV,main="Time Headway (s)",col="blue")
  lines(timeheadAV,col="red")
  legend(12,0.3,legend=c("timeheadHV","timeheadAV"),
         col=c("blue","red"), lty=1:1,cex=0.8)
  